package com.whq.knowverywell.util;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * String工具类
 * @author chengqinhui
 */
public class StringUtil {
    private static final String TAG = "StringUtil";

	public static boolean isEmpty(String str) {
		return str == null || str.length() == 0;
	}

	public static boolean isNotEmpty(String str) {
		return !StringUtil.isEmpty(str);
	}

	public static boolean isBlank(String str) {
	    if(str==null || "".equals(str.trim())){
	        return true;
	    }
	    return false;
	}

	public static boolean isNotBlank(String str) {
		return !StringUtil.isBlank(str);
	}
	
	/**
	 * 判断是否是手机号码
	 * 
	 * @param mobiles
	 * @return
	 */
	public static boolean isMobileNO(String mobiles) {
	    if (mobiles == null || "".equals(mobiles)) {
	        return false;
	    } else {
	        Pattern p = Pattern
	                .compile("^((13[0-9])|(15[^4,\\D])|(18[0,5-9]))\\d{8}$");
	        Matcher m = p.matcher(mobiles);
	        return m.matches();
	    }
	}
	
	
	/**
	 * 判断是否是邮箱
	 * 
	 * @param email
	 * @return
	 */
	public static boolean isEmail(String email) {
	    if (email == null || "".equals(email)) {
	        return false;
	    } else {
	        Pattern p = Pattern
	                .compile("\\p{Alpha}\\w{2,15}[@][a-z0-9]{3,}[.]\\p{Lower}{2,}");
	        Matcher m = p.matcher(email);
	        return m.matches();
	    }
	}
	
	/**
	 * 分解字符串，并且剔除空的元素。
	 * @param str
	 * @param regex
	 * @return
	 */
	public static List<String> split2list(String str, String regex) {
		List<String> retList = new ArrayList<String>();
		if (str == null) {
			return retList;
		}
		String[] words = str.split(regex);
		for (int i = 0; i < words.length; i++) {
			if ( (words[i] != null) 
					&& (!words[i].trim().equals(""))
					) {
				retList.add(words[i]);
			}
		}
		return retList;
	}
	
	
	public static boolean isNumeric(String str) {
	    Pattern pattern = Pattern.compile("[0-9]*");
        return pattern.matcher(str).matches();
	}
	
	public static boolean isPinYin(String str) {
		Pattern pattern = Pattern.compile("[ a-zA-Z]*");
        return pattern.matcher(str).matches();
	}
	
	public static boolean containCn(String str) {        
	    Pattern pattern = Pattern.compile("[\\u4e00-\\u9fa5]");          
	    return pattern.matcher(str).find();
	}
}
